<template>
  <div>
    <el-button-group style="display: flex; flex-direction: row; ">
      <template>
        <div v-for="(item, index) in buttonGroup.fields" :key="index" style="margin-right: 10px;">
          <template v-if="item.selected">
            <el-dropdown
              split-button
              :size="item.size ? item.size : buttonGroup.size"
              :type="item.type ? item.type: 'primary'"
              @command="item.callback"
            >
              {{ item.text }}
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  v-for="(item2, index2) in item.selectList"
                  :key="index2"
                  :command="{value: item2.value, operateType: item.operateType}"
                >
                  {{ item2.title }}
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
          <template v-else>
            <el-button
              v-if="item.showButtonGroup"
              :size="item.size ? item.size : buttonGroup.size"
              :type="item.type ? item.type: 'primary'"
              :icon="item.icon"
              @click="item.callback(item.operateType)"
            >
              {{ item.text }}
            </el-button>
          </template>

        </div>
      </template>
    </el-button-group>
  </div>
</template>

<script>
export default {
  name: 'OperationButton',
  props: {
    buttonGroup: { type: Object, default: null }
  }
}
</script>
